import instance from '@/utils/axios'


/* home首页接口 */

/* 1.文章频道接口 */
function getChannelList() {
    return instance({
        url:"/v1_0/channels",
        method:'get'
    })
}
export { getChannelList }

// 2.文章列表
function getArticleList({channel_id,timestamp}) {
    return instance({
        url:'/v1_0/articles',
        method:'get',
        params:{
            /* 固定参数，写1即可 */
            with_top:1,
            channel_id,
            timestamp
        }
    })
}
export { getArticleList }


// 获取文章详情
function getArticleInfo(id){
    return instance({
        url:`/v1_0/articles/${id}`,
        method:"get"
    })
}
export { getArticleInfo }

// 关注接口

function addFollowing(target){
    return instance({
        url:'/v1_0/user/followings',
        method:'post',
        data:{target}
    })
}

//取消关注
function removeFollowing(target){
    return instance({
        url:`/v1_0/user/followings/${target}`,
        method:'delete',
    })
}

export { addFollowing, removeFollowing }

//点赞
function addLikings(target){
    return instance({
        url:'/v1_0/article/likings',
        method:'post',
        data:{target}
    })
}

//取消点赞
function removeLikings(target){
    return instance({
        url:`/v1_0/article/likings/${target}`,
        method:'delete'
    })
}

export { addLikings ,removeLikings }

//不喜欢

function addDisLikes(target){
    return instance({
        url:"/v1_0/article/dislikes",
        method:'post',
        data:{target}
    })
}
//取消不喜欢
function removeDisLikes(target){
    return instance({
        url:`/v1_0/article/dislikes/${target}`,
        method:'delete'
    })
}

export { addDisLikes ,removeDisLikes }

function getSuggestion(q){
    return instance({
        url:'/v1_0/suggestion',
        method:'get',
        params:{q}
    })
}
export { getSuggestion }

function getSearchList({page,q}){
    return instance({
        url:'/v1_0/search',
        method:'get',
        params:{
            page,
            q
        }
    })
}
export { getSearchList }